using System.Linq;
using UnityEngine;
using QFramework;

namespace XCZProject
{
	/// <summary>
	/// 技能控制器，控制技能展示
	/// </summary>
	public partial class AbilityController : ViewController,IController
	{
		void Start()
		{
			// Code Here

			// 根据能力是否解锁来展示能力，如果unlocked是true，才会展示
			Global.SimpleSwordUnlocked.RegisterWithInitValue(unlocked =>
			{
				if (unlocked)
				{
					SimpleSword.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
			
			Global.SimpleKnifeUnlocked.RegisterWithInitValue(unlocked =>
			{
				if (unlocked)
				{
					SimpleKnife.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
			
			Global.RotateSwordUnlocked.RegisterWithInitValue(unlocked =>
			{
				if (unlocked)
				{
					RotateSword.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
			
			Global.BasketBallUnlocked.RegisterWithInitValue(unlocked =>
			{
				if (unlocked)
				{
					BasketBallAblity.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
			
			// 随机一个能力提升，List.where是一个筛选器，筛选出所有IsWeapon为true的能力，然后随机一个，然后调用Upgrade方法
			this.GetSystem<ExpUpgradeSystem>().Items.Where(self=>self.IsWeapon).ToList().GetRandomItem().Upgrade();

			Global.SuperBomb.RegisterWithInitValue(unlocked =>
			{
				if (unlocked)
				{
					SuperBomb.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
		}

		public IArchitecture GetArchitecture()
		{
			return Global.Interface;
		}
	}
}
